import Vue from 'vue'
import Router from 'vue-router'
import Ebook from '@/view/Ebook.vue'
import Eshelf from '@/view/Eshelf.vue'
import Error404 from '@/view/Error404.vue'
Vue.use(Router)
// router.beforeEach((to, from, next) => {
// 	if (to.matched.length === 0) {  // 如果未匹配到路由
// 	   from.name ? next({ name: from.name }) : next('/404')
// 	 } else {
// 	   next()  // 如果匹配到正确跳转
// 	 }
// })

export default new Router({

    routes: [
        {
            path: '/',
            redirect: '/Eshelf'
        },
        {
            path: '/Eshelf',
            component: Eshelf,
        },
        {
            path: '/Ebook',
            component: Ebook
        },
        {
            path: '/404',
            component: Error404
        },
        //当别的路由都不匹配时,匹配错误页面
        {
            path: '*',
            redirect: '/404'
        }
    ]
})